home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: sleep.C,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:56:02 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "thread.h"
- #include "timer.h"
- #include "thread_funcs.h"
- #include "thread_globals.h"
- #include "threadstate.h"
-
-
-
- /*
- * Wakeup is to be used for threads that are sleeping.
- * It does not work to try to wake up a thread that
- * is waiting on a semaphore or some other such thing.
- * For those, you MUST use notify().
- */
-
- BOOL AwakenedAThread = FALSE;
-
- void
- WakeUp( TCB *who )
- {
-
- TRPRINT(TR_THREAD, TR_LEVEL_1, ("WakeUp: thread %d, state %d",
- who->id, who->state));
-
- /*
- * Unlike with semaphores, this
- * thread is not on a list.
- * Only one thread can be awaiting a given
- * timer at any time.
- */
-
- /* This can get called by the timer or by anyone.
- * If the timer calls us and we have already been awakened,
- * we had better not barf.
- */
- if( who->state != THREAD_WAKEUP_WAIT ) {
- /* it is ok - do not barf - just ignore the wakeup */
- TRPRINT(TR_THREAD, TR_LEVEL_1, ("wakeup ignored"));
- return;
- }
- TRPRINT(TR_THREAD, TR_LEVEL_1, ("waking up thread %d", who->id));
-
- AwakenedAThread = TRUE;
- listEnq( &ReadyList, &(who->controlList) );
- }
-
- void
- Sleep( int seconds )
- {
- int newThreadState;
-
- SM_ASSERT(LEVEL_3, NOT_LIST_MEMBER(&(Active->controlList)));
-
- switch( seconds ) {
- case SLEEP_DONT_SLEEP:
- TRPRINT(TR_THREAD, TR_LEVEL_1,
- ("thread %d going to back of ready Q", Active->id));
- /*
- * Just put the current thread at the back of the ready list.
- * This thread will NOT be awakened by Wakeup ().
- */
-
- listEnq( &ReadyList, &(Active->controlList) );
- newThreadState = THREAD_READY_WAIT;
- break;
-
- default:
- TRPRINT(TR_THREAD, TR_LEVEL_1,
- ("thread %d setting timer for %d seconds", Active->id, seconds));
-
- ServerTimer.Start( (TIME)seconds,
- (TIMERFUNC) WakeUp, (TIMERARG) Active );
- Active->error = esmNOERROR;
- /* drop through: */
-
- case SLEEP_INDEFINITELY:
- TRPRINT(TR_THREAD, TR_LEVEL_1,
- ("thread %d sleeping %s", Active->id,
- seconds==SLEEP_INDEFINITELY?"indefinitely":""));
- /*
- * This thread must be awakened by Wakeup().
- * It is not going on an waitlist.
- * The thread that wakes us up must have a handle
- * on this tcb, probably by getting it from a net message
- * or a disk message.
- */
- newThreadState = THREAD_WAKEUP_WAIT;
- break;
- }
- dispatch( newThreadState );
- }
-
-
-